package com.tsingteng.cosfun.helper;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.tsingteng.cosfun.R;


/**
 * 描述: dialog辅助类
 * 创建人: 肖利
 * 时间: 2018/7/30
 * qq: (872179966)
 */

public class DialogHelper {

    private static Toast toast;
    private static TextView tvMessage;
    private static View view;

    public static Dialog getLoadingDialog(Context context) {
        Dialog dialog = new Dialog(context, R.style.dialog);
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
        dialog.setContentView(dialogView);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.CENTER);
        window.setDimAmount(0.1f);
        return dialog;
    }

    /**
     * 显示中间的提示框
     *
     * @param context
     * @return
     */
    public static Dialog getHintDialog(Context context) {
        Dialog dialog = new Dialog(context, R.style.dialog);
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_hint, null);
        dialog.setContentView(dialogView);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.CENTER);
        window.setDimAmount(0.1f);
        return dialog;
    }

    /**
     * 自定义Toast
     *
     * @param context
     * @param msg
     */
    public static void showHintToast(Context context, String msg) {
        if (toast == null) {
            toast = new Toast(context);
            //设置Toast显示位置，居中，向 X、Y轴偏移量均为0
            toast.setGravity(Gravity.CENTER, 0, 0);
            //获取自定义视图
            view = LayoutInflater.from(context).inflate(R.layout.dialog_hint, null);
            tvMessage = (TextView) view.findViewById(R.id.tv_load_dialog);
        }
        //设置文本
        tvMessage.setText(msg);
        //设置视图
        toast.setView(view);
        //设置显示时长
        toast.setDuration(Toast.LENGTH_SHORT);
        //显示
        toast.show();
    }
}
